package search.twothreetree.arrayStyle;

import java.util.Arrays;

/**
 * 2-3树节点
 *
 * @author liangzj9624@163.com
 * @date 2020/4/4 下午5:53
 */
public class Node23 {
    /**
     * 数据的数量,
     * 同时代表节点类型, 数据量为1时是2节点, 数据量为2时是3节点
     */
    int dataSize;

    /**
     * 数据
     */
    int[] datas;

    /**
     * 子节点
     */
    Node23[] childNodes;

    public Node23(int data) {
        this.dataSize = 1;
        this.datas = new int[dataSize];
        this.datas[0] = data;
        this.childNodes = new Node23[dataSize + 1];
    }

    public boolean isFull() {
        return dataSize == 2;
    }

    public boolean isLeaf() {
        return childNodes[0] == null;
    }

    public boolean isNode2() {
        return dataSize == 1;
    }

    @Override
    public String toString() {
        return "TwoThreeNode{" +
                "dataSize=" + dataSize +
                ", datas=" + Arrays.toString(datas) +
                ", childNodes=" + Arrays.toString(childNodes) +
                '}';
    }
}
